import unittest
import sys
import os

# 添加当前目录到Python路径
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from demo4 import quick_sort

class TestQuickSort(unittest.TestCase):
    def test_empty_list(self):
        """测试空列表"""
        self.assertEqual(quick_sort([]), [])
    
    def test_single_element(self):
        """测试单元素列表"""
        self.assertEqual(quick_sort([1]), [1])
    
    def test_sorted_list(self):
        """测试已排序的列表"""
        arr = [1, 2, 3, 4, 5]
        self.assertEqual(quick_sort(arr), [1, 2, 3, 4, 5])
    
    def test_reverse_sorted_list(self):
        """测试逆序列表"""
        arr = [5, 4, 3, 2, 1]
        self.assertEqual(quick_sort(arr), [1, 2, 3, 4, 5])
    
    def test_duplicate_elements(self):
        """测试包含重复元素的列表"""
        arr = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]
        self.assertEqual(quick_sort(arr), [1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9])
    
    def test_negative_numbers(self):
        """测试包含负数的列表"""
        arr = [-5, 3, -1, 0, 2, -3, 1]
        self.assertEqual(quick_sort(arr), [-5, -3, -1, 0, 1, 2, 3])
    
    def test_float_numbers(self):
        """测试浮点数列表"""
        arr = [3.14, 1.41, 2.71, 0.58, 1.73]
        self.assertEqual(quick_sort(arr), [0.58, 1.41, 1.73, 2.71, 3.14])
    
    def test_mixed_types(self):
        """测试混合类型列表"""
        arr = [1, "2", 3.0, 4]
        with self.assertRaises(TypeError):
            quick_sort(arr)

if __name__ == '__main__':
    unittest.main()
